import { useState } from 'react'
import { getResult } from '../../../api/search'
import { List, Cell } from 'react-vant';
export default ({ value }) => {
    const [list, setList] = useState([]);
    const [finished, setFinished] = useState(false);
    const [q, setQ] = useState(1);

    const parmas = {
        page: 1,
        per_page: 20,
        q
    }
    const onLoad = async () => {
        // 异步更新数据
        const data = await getData();
        setList((v) => [...v, ...data]);
        if (data.length === 0) {
            setFinished(true);
        }
    };
    async function getData() {
        const { data } = await getResult(parmas)
        console.log(data.data.results);
        setQ(v => v + 1)
        return data.data.results
    }

    return (<List finished={finished} onLoad={onLoad}>
        {list.length
            ? list.map((item, index) => {
                return <Cell key={item.index} title={item.title} />;
            })
            : null}
    </List>)
}